﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GestionEducativa.Models;


namespace GestionEducativa.DataLayer
{
    
    public class DetalleFacturaRepository
    {
        Gestion_EducativaEntities ObjectContex = new Gestion_EducativaEntities();


        public void InsertarDetalles(DetalleFactura df)
        {
            ObjectContex.AddToDetalleFactura(df);
            ObjectContex.SaveChanges();
        }

        public void BorrarDetalle(int idd)
        {
            DetalleFactura df = (from dfx in ObjectContex.DetalleFactura where dfx.iddetalle == idd select dfx).First();
            ObjectContex.DetalleFactura.DeleteObject(df);
            ObjectContex.SaveChanges();
        }

        public void ActualizarDetalle(DetalleFactura dft)
        {
            DetalleFactura df = ObjectContex.DetalleFactura.First(dfx => dfx.iddetalle == dft.iddetalle);

            df.idfactura = dft.idfactura;
            df.idconcepto = dft.idconcepto;

            ObjectContex.SaveChanges();
        }

        public IEnumerable<DetalleFactura> TraerDetallesFactura(int idf)
        {
            IEnumerable<DetalleFactura> DataListDetalle = (from dfx in ObjectContex.DetalleFactura where dfx.idfactura == idf select dfx).AsEnumerable();
            return DataListDetalle;
        }

        public IEnumerable<DetalleFactura> TraerTodosDetallesFactura()
        {
            IEnumerable<DetalleFactura> DataListDetalle = (from dfx in ObjectContex.DetalleFactura select dfx).AsEnumerable();
            return DataListDetalle;
        }

        public DetalleFactura TraerUnDetalleFactura(int idd)
        {
            DetalleFactura df = (from dfx in ObjectContex.DetalleFactura where dfx.idfactura == idd select dfx).First();
            return df;
        }
    }
}